// 游戏逻辑相关的帮助函数

helper = {
    
    CELLS_UP_BASE : cc.p(0,510), 
    CELLS_DOWN_BASE : cc.p(0,430),

    SIDE_DOWN : 0,
    SIDE_UP : 1,

    CELL_SIZE : 80, // 格子大小

    // 车库大小
    GARAGE_WIDTH : 640,
    GARAGE_HEIGHT : 320,

    // 背包大小
    BAG_WIDTH : 10,
    BAG_HEIGHT : 3,
    BAG_CELL_SIZE : 56, // 格子大小

    // 攻击评价
    ATTACK_GRADE_MISS : 0,
    ATTACK_GRADE_BAD : 1,
    ATTACK_GRADE_GOOD : 2,
    ATTACK_GRADE_PERFECT : 3,

    // 战斗格子坐标转成屏幕坐标
    /* 
    上:
    (0,3) (1,3) ... (7,3)
    ...
    (0,1) (1,1) ... (7,1)
    (0,0) (1,0) ... (7,0)
    
    下 车库:
    (0,0) (1,0) ... (7,0)
    (0,1) (1,1) ... (7,1)
    ...
    (0,3) (1,3) ... (7,3)
    */
    posCell2Scene : function (cx, cy, side) {
        var base = cc.p(0,0);
        if (side == helper.SIDE_DOWN) base = helper.CELLS_DOWN_BASE;
        if (side == helper.SIDE_UP) base = helper.CELLS_UP_BASE;
        var pos = this.posCell2Garage(cx, cy, side);
        return cc.pAdd(pos, base);
    },

    posCell2Garage : function (cx, cy, side) {
        var L = helper.CELL_SIZE;
        var pos = cc.p(0,0); // 必须新建一个Point
        pos.x = cx * L + L/2;
        pos.y = (side == helper.SIDE_UP) ? (cy * L + L/2) : (- cy * L - L/2); 
        return pos;
    },

    // 获取某个story的mission ids
    getMissionIdsByStory : function (storyId) {
        var res = [];
        for(var id in TB_mission) {
            if (TB_mission[id].story_id == storyId) {
                res.push(id);
            };
        }
        return res;
    },

    // 背包坐标
    posCell2Bag : function (cx, cy) {
        var pos = cc.p(0,0);
        pos.x = helper.BAG_CELL_SIZE * ( cx + 1/2 );
        pos.y = helper.BAG_CELL_SIZE * ( helper.BAG_HEIGHT - cy - 1/2);
        return pos;
    },

};
